#!/bin/bash
echo -e -n "\e[31;40m 必须要先设置主机名且必须相同(y/n): \e[0m"
read pan

sed -i '$a192.168.200.11 mysql1' /etc/hosts
sed -i '$a192.168.200.12 mysql2' /etc/hosts
sed -i '$a192.168.200.13 mycat' /etc/hosts


cd /etc/yum.repos.d/

rm -rvf *

cat >>centos.repo<<OK
[centos]
name=centos
baseurl=ftp://192.168.200.11/centos
gpgcheck=0
enable=1
[gpmall]
name=gpmall
baseurl=ftp://192.168.200.11/gpmall-repo
gpgcheck=0
enable=1
OK

cd


yum clean all
yum install -y mariadb mariadb-server

systemctl restart mariadb

sed -i '$a[mysqld]' /etc/my.cnf
sed -i '$alog_bin = mysql-bin' /etc/my.cnf
sed -i '$abinlog_ignore_db = mysql' /etc/my.cnf
sed -i '$aserver_id = 20' /etc/my.cnf

systemctl restart mariadb

sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config

systemctl stop firewalld.service
systemctl disable firewalld.service
iptables -F
iptables -X
iptables -Z
service iptables save

sql1="change master to master_host='mysql1',master_user='user',master_password='000000';"
sql2="start slave;"
sql3="show slave status\G"
mysql -uroot -p${PASSWORD} -e "${sql1}"
mysql -uroot -p${PASSWORD} -e "${sql2}"
mysql -uroot -p${PASSWORD} -e "${sql3}"

